<template>
  <el-dialog title="项目信息录入" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
    <el-form :model="project" label-width="120px" class="demo-form-inline">
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目名称">
            <el-input v-model="project.pName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目编码">
            <el-input v-model="project.pCode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目简称">
            <el-input v-model="project.pJc"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目金额">
            <el-input v-model="project.pMoney"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目地址">
            <el-input v-model="project.pAddr"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目工期(月)">
            <el-input v-model="project.pUration"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="开工时间">
            <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期"
              v-model="project.startTime"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="竣工时间">
            <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期"
              v-model="project.endTime"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="隧道数量">
            <el-input v-model="project.tunnelNum"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注">
            <el-input type="textarea" v-model="project.bz"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from '../../../api'
import qs from 'qs'
export default {
  data() {
    return {
      dialogVisible: false,
      //项目信息
      tunnelList: [],
      etypeList: [],
      project: {
        pName: '',
        pCode: '',
        pJc: '',
        pMoney: '',
        pAddr: '',
        pUration: '',
        startTime: '',
        endTime: '',
        tunnelNum: '',
        pStatus: '',
        bz: ''
      }
    }
  },
  mounted() {
    this.$bus.$on('onAddProject', (flag) => {
      this.dialogVisible = flag
    })
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => { })
    },
    create() {
      api
        .proAdminsave(qs.stringify(this.project))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
            this.dialogVisible = false
            this.$bus.$emit('onRefreshProAdmin', true)
          } else {
            this.$message({
              type: 'fail',
              message: res.data.message
            })
            console.log(res.data.message)
          }
        })
        .catch((err) => { })
    },

    onSubmit() {
      console.log('submit!')
    }
  }
}
</script>

<style>

</style>